<template>
	<div class="regBox" v-if="is_show">
		<div class="regBox_pub"></div>
		<div class="regBox_main">
			<b>{{$t('h_pcreg.title1')}}</b>
			<div class="forms">
				<el-input :placeholder="$t('h_pcreg.title2')" v-model="formData.username">
					<i slot="prefix" class="el-input__icon el-icon-s-custom"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
			
				<el-input :placeholder="$t('h_pcreg.title3')" v-model="formData.password" type="password">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				
				<el-input :placeholder="$t('h_pcreg.title4')" v-model="formData.password_cp" type="password">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				

				<el-input :placeholder="$t('l_qingshuruxingming')" v-model="formData.real_name" type="text">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				<el-input :placeholder="$t('h_pcreg.title17')" v-model="formData.invite_code" type="text"  v-if="config.is_regtj_1==1">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
			
				<div class="msg">
					<el-checkbox v-model="checked">
					</el-checkbox>
					<span>{{$t('h_pcreg.title5')}}</span>
					<i @click="openUserMsg">{{$t('h_pcreg.title6')}}</i>
				</div>
				<button class="submit" @click="submit">{{$t('h_pcreg.title1')}}</button>
				
				<div class="aas">
					<span> </span>
					<span @click="openLogin">{{$t('h_pcreg.title7')}}</span>
				</div>
			</div>
			<div class="closeBtn" @click="closeReg">
				
			</div>
		</div>
		
		
	</div>
</template>

<script>
	export default {
		data() {
			return {
				is_show:false,
				checked:true,
				formData: {
					username: '',
					password: '',
					password_cp: '',
					invite_code:"",//邀请码
					real_name:"",//真实姓名
				},
				config:{}
			};
		},
		mounted(){
			if(localStorage.getItem('inviteCodeValue')){
				this.formData.invite_code=localStorage.getItem('inviteCodeValue')
			}
			
			let that = this;
				this.$api.ConfigGetConfig({
					key: 'app_down_url',
				}, (res) => {
				
					if (res.code == 0) {
						that.config=res.data[1].value;

					
						// window.open(res.data[0].value)
						// that.$router.push('../../index/downloadapp?url=' + res.data[0].value)
					} else {
						// that.$message.error(res.msg);
					}
				})
		},
		methods: {
			openReg(){
				this.is_show = true
			},
			closeReg(){
				this.is_show = false
			},
			openLogin(){
				this.closeReg()
				this.$parent.openLogin()
			},
			openUserMsg(){
				this.$parent.openUserMsg()
			},
			submit(){
				if(!this.formData.username) return this.$message(this.$t('h_pcreg.title8'));
				let reg =/^[a-zA-Z\d]\w{4,7}[a-zA-Z\d]$/;
				let re = new RegExp(reg)
				if(!re.test(this.formData.username)) return this.$message(this.$t('h_pcreg.title9'));
				if(!this.formData.password || !this.formData.password_cp) return this.$message(this.$t('h_pcreg.title10'));
				if(this.formData.password != this.formData.password_cp) return this.$message(this.$t('h_pcreg.title11'));
				let reg1 =/^[a-zA-Z\d]\w{4,14}[a-zA-Z\d]$/;
				let re1 = new RegExp(reg);
				if(!re1.test(this.formData.password)) return this.$message(this.$t('h_pcreg.title12'));
				if(!this.checked) return this.$message(this.$t('h_pcreg.title13'));
				
				console.log('注册前')	
				const loading = this.$loading({
					    lock: true,
					    text: 'Loading',
					    spinner: 'el-icon-loading',
					    background: 'rgba(0, 0, 0, 0.7)'
					});
					this.$api.loginReg(this.formData,(res)=>{
						loading.close();
						if(res.code == 0){
								localStorage.setItem('token',res.data)
								localStorage.setItem('first',1)
									this.$parent.reloadUserInfo();
									window.location.href='/'
									this.closeReg()
							
							// this.$api.caipiaoLoginReg({username:this.formData.username,password:this.formData.password}, (res2) => {
							// 	if (res2.code == 0) {
							// 		console.log(res2)
							// 		localStorage.setItem('member_sessionid',res2.data.data.member_sessionid)
							// 		localStorage.setItem('member_auth_id',res2.data.data.member_auth_id)
							// 		localStorage.setItem('token',res.data)
							// 		this.$parent.reloadUserInfo();
							// 		this.closeReg()
							// 	} else {
							// 		this.$message.error(res2.msg);
							// 	}
							// });
						

							
						}else{
							this.$message.error(res.msg);
						}
					})
				return
				this.$parent.openverifyBox((code,key)=>{
					this.formData.code = code
					this.formData.key = key
					this.formData.reg_domain = window.location.hostname
					let reg_share_domain = localStorage.getItem('reg_share_domain')?localStorage.getItem('reg_share_domain'):'';
					this.formData.reg_share_domain = reg_share_domain
					let share_code = localStorage.getItem('share_code')?localStorage.getItem('share_code'):'';
					this.formData.share_code = share_code
					const loading = this.$loading({
					    lock: true,
					    text: 'Loading',
					    spinner: 'el-icon-loading',
					    background: 'rgba(0, 0, 0, 0.7)'
					});
					this.$api.loginReg(this.formData,(res)=>{
						loading.close();
						if(res.code == 0){
							localStorage.setItem('token',res.data)
									this.$parent.reloadUserInfo();
									this.closeReg()
							// this.$api.caipiaoLoginReg({username:this.formData.username,password:this.formData.password}, (res2) => {
							// 	if (res2.code == 0) {
							// 		console.log(res2)
							// 		localStorage.setItem('member_sessionid',res2.data.data.member_sessionid)
							// 		localStorage.setItem('member_auth_id',res2.data.data.member_auth_id)
							// 		localStorage.setItem('token',res.data)
							// 		this.$parent.reloadUserInfo();
							// 		this.closeReg()
							// 	} else {
							// 		this.$message.error(res2.msg);
							// 	}
							// });
						

							
						}else{
							this.$message.error(res.msg);
						}
					})
				})
				
			}
		}
	}
</script>

<style lang="less" scoped>
	.regBox {
		position: fixed;
		z-index: 1000;
		width: 100vw;
		height: 100vh;
		overflow-y: overlay;
		top:0;
		left: 0;
		
		.closeBtn{
			position: absolute;
			border-radius: 50%;
			z-index: 3;
			bottom: -.9rem;
			left: 0;
			right: 0;
			margin: auto;
			width: 0.5984rem;
			height: 0.5984rem;
			background-image: url(/icons/main.png);
			background-position: -5.1136rem -4.2024rem;
			background-size: 8.296rem 7.7928rem;
		}
		&_pub {
			position: fixed;
			z-index: 1;
			width: 100vw;
			height: 100vh;
			width: 100vw;
			height: 100vh;
			background: rgba(0, 0, 0, .6);
		}

		&_main {
			position: absolute;
			z-index: 2;
			background-color: var(--theme-main-bg-color);
			border: thin solid;
			border-color: var(--theme-color-line);
			border-radius: 0.2rem;
			position: absolute;
			top: 20vh;
			left: 0;
			right: 0;
			width: 6rem;
			// height: 8rem;
			margin: auto;

			.forms {
				// max-height: 7rem;
				overflow-x: hidden;
				overflow-y: overlay;
				padding: 0 0.36rem;
				display: flex;
				flex-direction: column;
			}
			.el-input{
				margin: 0 0 .32rem;
			}
			p {
				font-size: .18rem;
				height: 0.4rem;
				line-height: 1;
				color: var(--theme-secondary-color-error);
				margin: .16rem 0 .06rem .16rem;
				opacity: .7;
			}

			b {
				margin: 0.2rem 0 0.4rem;
				color: var(--theme-text-color-darken);
				font-size: .32rem;
				font-weight: 700;
				height: 0.34rem;
				display: block;
				text-align: center;
			}
			.msg{
				display: flex;
				margin-bottom: .3rem;
				span{
					font-size: .26rem;
					color: var(--theme-text-color-lighten);
					margin: 0 0 0 .1rem ;
				}
				i{
					font-size: .26rem;
					font-style: normal;
					color: var(--theme-primary-color);
				}
			}
			.submit{
				background-color: var(--theme-primary-color);
				border-color: var(--theme-primary-color);
				border-radius: 0.14rem;
				height: .8rem;
				line-height: .8rem;
				display: block;
				color: var(--theme-primary-font-color);
				font-size: .24rem!important;
			}
			.aas{
				display: flex;
				margin: .3rem 0;
				span{
					flex: 1;
					display: block;
					text-align: center;
					font-size: .24rem;
					color: var(--theme-primary-color);
				}
			}
		}
	}
</style>